﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace MuXue.Zyiz.Template.Infrastructure
{
    public class UnitOfWork : IUnitOfWork, IDisposable
    {
        private IDbContext _Context;
        public UnitOfWork(IDbContext Context)
        {
            _Context = Context;
        }
        public int Commit()
        {
            return _Context.SaveChanges();
        }
        public async Task<int> CommitAsync()
        {
          return   await _Context.SaveChangesAsync(CancellationToken.None);
        }
        public void Dispose()
        {
            if (_Context != null)
            {
                _Context.Dispose();
            }
            GC.SuppressFinalize(this);
        }
    }
}
